package com.live.stamp.web.im.controller;

import com.live.stamp.base.token.TokenAuth;
import com.live.stamp.web.im.service.ImService;
import org.springframework.boot.container.core.common.BusinessException;
import org.springframework.boot.container.core.common.ServerResponse;
import org.springframework.boot.container.core.controller.BaseRestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author cwd E-mail: wendong.cao@jsxfedu.com
 * @version 1
 * @date 2018/4/20 10:02
 */
@RestController
@RequestMapping("/im")
public class ImController extends BaseRestController{

    @Resource
    private ImService imService;

    /**
     * @api {post} /im/getImToken 获取im token
     * @apiSampleRequest /im/getImToken
     * @apiName getImToken
     * @apiGroup im
     * @apiDescription 获取im token
     * @apiParam {String} token         token
     * @apiParamExample {json} 参数示例:
     * {
     *
     * }
     * @apiSuccessExample {json} 返回示例:
     * HTTP/1.1 200 OK
        {
            "code": 200,
            "msg": "",
            "data": {
                "code": 200,
                "userId": "1131d756162d2de8e0895106ECE8932320DB52A8812F90BCE3B",
                "token": "2QoPZtCwsLyDRG1yIK9h70nql7iz/RpG/P0Ag8WC10r1/1Ct7pnO7Oij3dsw234qRCr6DevHVgrZW5JUvSBpxc75xxrGjzMXDp8aM9KOZtQTNr21tpuMhQOzES4vq1HlhxHpFKkhwfeazOTW+00UtfJ3tBiS1qcghDU2IGwyNhs="
            }
        }
     */
    @TokenAuth
    @RequestMapping("/getImToken")
    public ServerResponse getImToken() {
        ServerResponse serverResponse = new ServerResponse();
        try{
            serverResponse.setCode(200);
            serverResponse.setData(imService.getImToken());
        }catch (BusinessException e) {
            serverResponse.setCode(ServerResponse.ERROR_BBUSINESS);
            serverResponse.setMsg(e.getMessage());
        }
        return serverResponse;

    }
}
